package com.zhoutao.blog.seven.model.converter;

import com.zhoutao.blog.seven.dao.model.TagDao;
import com.zhoutao.blog.seven.model.enums.TagColor;
import com.zhoutao.blog.seven.model.response.Tag;
import org.springframework.stereotype.Component;

@Component
public class TagConverter extends AbstractConverter<TagDao, Tag> {

    @Override
    public Tag converterFrom(TagDao tagDao) {
        Tag tag = new Tag();
        return tag.setId(tagDao.getId())
                .setColor(TagColor.findByOrdinal(tagDao.getId().intValue()).getValue())
                .setName(tagDao.getName());
    }

    @Override
    public TagDao converterTO(Tag tag) {
        return new TagDao().setId(tag.getId())
                .setColor(tag.getColor())
                .setName(tag.getName());
    }
}
